﻿using AutoMapper;
using ManagementApi.Models.System.TableLog;
using Modules;
using Modules.SMS;
using Modules.SMS.Entitys;
using PmSoft;

namespace ManagementApi.Models.Logs;

public class SmsSendLogDto
{
    /// <summary>
    ///
    ///</summary>
    public string MsgId { get; set; }

    /// <summary>
    /// 手机号码
    ///</summary>
    public string Phone { get; set; }

    /// <summary>
    /// 消息类型 (1:验证码 2.....)
    ///</summary>
    public MsgType MsgType { get; set; }

    public string MsgTypeName { get; set; }

    /// <summary>
    /// 消息内容
    ///</summary>
    public string MsgContent { get; set; }

    /// <summary>
    /// 状态(1:发送成功  0:发送失败)
    ///</summary>
    public int Status { get; set; }

    /// <summary>
    /// 验证码
    ///</summary>
    public string? VerificationCode { get; set; }

    /// <summary>
    /// 返回内容
    ///</summary>
    public string ResultMsg { get; set; }

    /// <summary>
    /// 是否已使用
    /// </summary>
    public bool IsUsed { get; set; }

    /// <summary>
    /// 发送时间
    ///</summary>
    public DateTime? CreateTime { get; set; }
    /// <summary>
    /// 扩展字段
    /// </summary>
    public string? Extend1 { get; set; }
}

public static partial class SmsSendLogExceptions
{
    public static SmsSendLogDto AsDto(this SmsSendLog entity)
    {
        SmsSendLogDto dto = new();
        var mapper = ServiceAccessor.GetService<IMapper>();
        mapper.Map(entity, dto);
        dto.MsgTypeName = entity.MsgType.GetDescription();
        return dto;
    }
}
